SQL queries that use EXISTS
subqueries are inefficient because the subquery is re-run for every row in the outer query’s table. There
are more efficient ways to write most queries, ways that do not use the EXISTS
condition.
Noncompliant code example
SELECT e.name
FROM employee e
WHERE EXISTS (SELECT * FROM department d WHERE e.department_id = d.id AND d.name = 'Marketing')
Compliant solution
SELECT e.name
FROM employee e INNER JOIN department d
ON e.department_id = d.id AND d.name = 'Marketing'